from django.db import models
import datetime

class Category(models.Model):
    name = models.CharField(max_length=20, unique=True)
    order = models.SmallIntegerField()
    art_count = models.IntegerField(default=0)

    def __unicode__(self):
        return self.name


class Article(models.Model):
    title = models.CharField(max_length=100)
    summary = models.TextField()
    content = models.TextField()
    post_time = models.DateTimeField(default=datetime.datetime.now())
    view_count = models.IntegerField(default=0)
    comm_count = models.IntegerField(default=0)
    category = models.ForeignKey(Category)

    def __unicode__(self):
        return self.title


class Comment(models.Model):
    name = models.CharField(max_length=20)
    mail = models.EmailField()
    url = models.URLField()
    content = models.TextField()
    post_time = models.DateTimeField(default=datetime.datetime.now())
    article = models.ForeignKey(Article)

    def save(self):
        self.post_time=datetime.datetime.now()
        return super(Comment, self).save()

    def __unicode__(self):
        return self.name